$(function(){
	TiaoBan1();
	TiaoBan2();
	
	//双击行事件
	$("#TiaoBandg").datagrid({
		//rowData是当前选中行的数据，是json字符串格式
		onDblClickRow:function(rowIndex,rowData){
			$("#TiaoBanwin").window("open");
			$('#TBmbbz').combobox({
				url:'KaoQinKa',
				valueField:'CWASID',
				formatter:function(row){
		               row.TEMNAME = row.TEMNAME+"   考勤卡："+row.CWASID;
		               return row.TEMNAME;
		        },
		        textField:"TEMNAME"
			});
			$("#TBid").val(rowData["EMPID"]);
			$("#TBcwaid").val(rowData["CWASID"]);
			$("#TBname").val(rowData["EMPNAME"]);
			$("#TBbm").val(rowData["DEPTNAME"]);
			$("#TBbz").val(rowData["TEMNAME"]);
			$("#TBbc").val(rowData["SHFNAME"]);

			$('#TByy').combobox('reload');
		}
	});
	
	//点击提交
	$("#TBadd").click(function(){
		var empid = $("#TBid").val();
		var cwaid = $("#TBcwaid").val();
		
		var cwasid = $("#TBmbbz").val();		
		var rsnid = $("#TByy").val();
		var sstrem = $("#TBbzz").val();
		
		
		$.ajax({
			url:"updateTB",
			type:"post",
			data:{"empid":empid,"cwaid":cwaid,"cwasid":cwasid,"rsnid":rsnid,"sstrem":sstrem},
			success:function(data){
				$('#TiaoBandg').datagrid('reload');
				$('#TiaoBanJiLudg').datagrid('reload');
			}
		});
		
//		//清空表单
//		$("#RSNID").val("");
//		$("#RSNREASON").val("");
//		$("#RSNREM").val("");   
//		
		
		$("#TiaoBanwin").window("close");
	});
	
	
});

function TiaoBan1(){
	//初始化表格
	$('#TiaoBandg').datagrid({
	    url:'BanZuRenYuan',
	    /* queryParams:{
	    	deptno:10
	    }, */
	    columns:[[
			{field:'KPRID',checkbox:true,width:1,title:'排班编号',align:'center'},
			{field:'CWASID',title:'所属考勤卡',width:1,align:'center'},
			{field:'EMPID',title:'员工id',width:1,align:'center',hidden:true},
			{field:'EMPNAME',title:'员工姓名',width:1,align:'center'},
			{field:'DEPTNAME',title:'部门',width:1,align:'center'},
			{field:'TEMNAME',title:'班组',width:1,align:'center'},
			{field:'SHFNAME',title:'班次',width:1,align:'center'},
			{field:'SHFREM',title:'班次时间',width:1,align:'center'},
			{field:'KPRTIME',title:'更改时间',width:1,align:'center',
				formatter: function(value,row,index){
					if(!isNaN(value)){
						return "";
					}
					return new Date(value).getFullYear() + '-' + (new Date(value).getMonth() + 1) + '-' + new Date(value).getDate() + ' ' + new Date(value).getHours() + ':' + new Date(value).getMinutes() + ':' + new Date(value).getSeconds();
				}
			},
			{field:'CWASREM',title:'备注',width:1,align:'center'}
		]],
	    pagination:true,
	    pageNumber:1,
	    pageSize:5,
	    pageList:[5,10,15]
	});
}
function TiaoBan2(){
	//初始化表格
	$('#TiaoBanJiLudg').datagrid({
	    url:'TiaoBan',
	    /* queryParams:{
	    	deptno:10
	    }, */
	    columns:[[
			{field:'SSTID',checkbox:true,title:'原因编号',width:100,align:'center'},
			{field:'CWASID',title:'当前考勤卡',width:1,align:'center'},
			{field:'EMPNAME',title:'员工姓名',width:1,align:'center'},
			{field:'DEPTNAME',title:'部门',width:1,align:'center'},
			{field:'YTEMNAME',title:'原班组',width:1,align:'center'},
			{field:'MTEMNAME',title:'目标班组',width:1,align:'center'},
			{field:'RSNREASON',title:'调班原因',width:1,align:'center'},
			{field:'SSTTIME',title:'调班时间',width:2,align:'center',
				formatter: function(value,row,index){
					return new Date(value).getFullYear() + '-' + (new Date(value).getMonth() + 1) + '-' + new Date(value).getDate() + ' ' + new Date(value).getHours() + ':' + new Date(value).getMinutes() + ':' + new Date(value).getSeconds();
				}
			},
			{field:'SSTREM',title:'备注',width:1,align:'center'}
		]],
	    toolbar:'#TiaoBantb',
	    pagination:true,
	    pageNumber:1,
	    pageSize:5,
	    pageList:[5,10,15]
	});
}